<template>
  <div class="card-wrap flex-column justify-end card-padding" v-if="form.supplier">
    <el-form :model="form" :rules="type !== 'detail'?rules:{}" ref="cationInformation" label-width="140px" :label-position="type =='detail'?'right':'top'">
      <div class="card-title-wrap">
        <span>申请信息</span>
        <span></span>
      </div>
      <div :style="{marginLeft: (type == 'detail'?'':'50px')}">
        <el-form-item label="说明:" prop="supplier.applicationNotes">
          <el-input v-if="type !=='detail'" style="width: 70%" type="textarea" placeholder="请输入说明" v-model="form.supplier.applicationNotes" maxlength="500" :rows="5" show-word-limit></el-input>
          <span v-if="type =='detail'">{{ form.supplier.applicationNotes }}</span>
        </el-form-item>
        <el-form-item label="附件:" prop="supplier.applicationAttachments">
          <ImageCommon v-if="type !=='detail'" :up-type="2" info="选择附件" :limit="5" v-model="form.supplier.applicationAttachments" ></ImageCommon>
          <ImageCommon v-if="type =='detail'" :up-type="2" info="选择附件" v-model="form.supplier.applicationAttachments" disabled></ImageCommon>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import SearchContent from "@/components/SearchContent/index.vue";
export default {
  // 客户信息
  name: 'cationInformation',
  components: {
    SearchContent
  },
  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: '',
    },
  },
  computed: {
    form: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      },
    },
    type() {
      let status
      switch (this.state) {
        case 'write':
          status = 'edit'
          break
        case 'disabled':
          status = 'detail'
          break
        case 'readonly':
          status = 'detail'
          break
        case 'detail':
          status = 'detail'
          break
        case 'edit':
          status = 'edit'
        case 'add':
          status = 'add'
          break
      }
      return status
    },
  },
  data() {
    return {
      rules: {
        supplier: {
          applicationNotes: [
            {
              required: true,
              message: '请输入说明',
              trigger: 'change',
            },
          ]
        }
      },
    };
  },
  created() {

  },
  methods: {
    valid() {
      return new Promise(async (resolve) => {
        let result = true;
        let refs = Object.values(this.$refs);
        for (let index = 0; index < refs?.length; index++) {
          const ref = refs[index];
          if (Object.prototype.toString.call(ref) == "[object Array]") {
            for (let i = 0; i < ref.length; i++) {
              const element = ref[i];
              if (element?.valid) {
                let rc = await element?.valid?.();
                result = result && rc;
              }
              if (element?.validate) {
                let rf = await this._valid(ref);
                result = result && rf;
              }
              if (element?.form_validate) {
                let rf = await this._valid(ref, "form_validate");
                result = result && rf;
              }
            }
          } else {
            if (ref?.valid) {
              let rc = await ref?.valid?.();
              result = result && rc;
            }
            if (ref?.validate) {
              let rf = await this._valid(ref);
              result = result && rf;
            }
            if (ref?.form_validate) {
              let rf = await this._valid(ref, "form_validate");
              result = result && rf;
            }
          }
        }
        resolve(result);
      });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
